package com.cwh.taskcenter.domain.notice.strategy.impl;

import com.cwh.taskcenter.domain.notice.model.SendTaskNotification;
import com.cwh.taskcenter.domain.notice.strategy.NotificationStrategy;
import com.cwh.taskcenter.domain.system.domainservice.MailSendDomainService;
import com.cwh.taskcenter.notice.email.dto.EmailConfigDTO;
import com.cwh.taskcenter.notice.email.dto.MailSendMessageDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author cwh
 */
@Component("EMAIL")
@Slf4j
public class EmailNotificationStrategy implements NotificationStrategy {

    @Autowired
    private MailSendDomainService mailSendDomainService;

    @Override
    public void send(SendTaskNotification notification) {
        log.info("发送邮件通知");
        EmailConfigDTO emailConfig = (EmailConfigDTO) notification.getChannelConfig();
        MailSendMessageDTO message = new MailSendMessageDTO();
        message.setAccountId(notification.getAccountId());
        message.setTitle(emailConfig.getSubject());
        message.setContent(emailConfig.getContent());
        message.setNickname(notification.getNickname());
        message.setMail(notification.getMail());
        message.setUserId(notification.getUserId());
        mailSendDomainService.doSendMail(message);
    }
}
